
///TITLE: Examining public support for comprehensive policy packages to tackle unhealthy food environments *****

**********Loading data***********
clear all
 import delimited "/Users/simone/Downloads/Day 2/Exercise/Stata/WP1.1 Final Survey (Only Completes, Concat).csv", delimiter(comma)
 
**********************************DATA CLEANING AND MANAGEMENT*******************************************
 
**********Eliminating speeders***********
 drop if durationinseconds < 600 // Drop participants who take less than 10 minutes to complete (speeders)
drop if (age==.&gender==.)

**********Cleaning height and weight data***********
destring height weight, replace force
replace height = 180 in 517 
replace height = . in 875 //875, 1088 and 554 were input incorrectly. Changed to missing values
replace weight = . in 875
replace weight = . in 1088
replace height = . in 1088
replace height = . in 554
replace weight = . in 554
replace weight = . in 765
replace weight = . in 64
replace weight = . in 156
replace weight = . in 263
replace weight = . in 568

*****Missing values for gender and nutrition-related disease - eliminating non-binary or prefer not to say*******
mvdecode gender, mv(3=.a \ 4=.b) // generate missing values for 'non-binary' and 'I prefer not to say'for gender
mvdecode nutrition_disease_1 nutrition_disease_2 nutrition_disease_3 nutrition_disease_4, mv (3=.) // generate missing value for 'I prefer not to say' for nutrition disease

**********Recode section***********
recode age (2 = 1) (3 = 2) (4 = 3)(5 = 4)(6 = 5)(7 = 6) //recode age bc it was coded 2-7 instead of 1-6
recode nutrition_disease_1 nutrition_disease_2 nutrition_disease_3 nutrition_disease_4 (2 = 0) // recode nutrition disease so that '1' is presence of disease and '0' is no disease
recode parental_status (2 = 0) (1 = 1) //record parental status bc '2' was no, so now we will make it zero

**********Re-naming variables***********
rename nutrition_disease_1 hypertension //re-naming nutrition related diseases (four lines)
rename nutrition_disease_2 cholesterol
rename nutrition_disease_3 CVD
rename nutrition_disease_4 diabetes
rename fairness_ks inequality_ks // re-naming fairness to inequality (greater on the scale means higher perception of inequality)
rename fairness_vatinc inequality_vatinc
rename fairness_vatdec inequality_vatdec
rename fairness_tax inequality_tax
rename fairness_nuted inequality_nuted
rename fairness_public inequality_public

****************************************DEMOGRAPHICS*******************************************************

**********Calculating bmi and creating bmi categories***********
gen heightmeters = height/100
gen heightsq = heightmeters^2
generate bmi = weight / heightsq
generate bmi_cat =.
replace bmi_cat = 0 if bmi<18.5 & bmi>1
replace bmi_cat = 1 if bmi>18.5 & bmi<25
replace bmi_cat = 2 if bmi>25 & bmi<30
replace bmi_cat = 3 if bmi>30 & bmi<65
replace bmi_cat = 4 if bmi==.

**********Collpasing employment categories - categorical***********
generate employment1_cat =.
replace employment1_cat = 0 if employment==1 | employment==2 //full or part time
replace employment1_cat = 1 if employment==3 | employment==4 //temporarily laid off or unemployed
replace employment1_cat = 2 if employment==5 //retired
replace employment1_cat = 3 if employment>5 //homemaker,disabled,student, other
tab employment1_cat

**********Collapsing employment - binary (yes/no)***********
generate employment2_cat =.
replace employment2_cat = 0 if employment>3 | employment==3
replace employment2_cat = 1 if employment<3
tab employment2_cat

**********Collapsing diet-related disease - binary (yes/no)***********
generate nutritiondisease_cat =.
replace nutritiondisease_cat = 0 if hypertension==0 | cholesterol==0 | CVD==0 | diabetes==0 // no nutrition-related disease
replace nutritiondisease_cat = 1 if hypertension==1 | cholesterol==1 | CVD==1 | diabetes==1 // yes nutrition-related disease

**********Collapsing political leaning - far left, left of center, center, right of center, far right***********
generate politicallean_cat =.
replace politicallean_cat = 0 if political_leaning==1 | political_leaning==2 // far left
replace politicallean_cat = 1 if political_leaning==3 | political_leaning==4 // left of center
replace politicallean_cat = 2 if political_leaning==5 | political_leaning==6 // center
replace politicallean_cat = 3 if political_leaning==7 | political_leaning==8 //right of center
replace politicallean_cat = 4 if political_leaning==9 | political_leaning==10 //far right

**********Collapsing regional residence - east vs. west germany***********
generate formergdr =.
replace formergdr = 0 if region==1 | region==2 | region==3 | region==5 | region==6 | region==7 | region==9 | region==10 | region==11 | region==12 | region==15
replace formergdr = 1 if region==4 | region==8 | region==13 | region==14 | region ==16 //Includes Mecklenburg-Vorpommern (8), Brandenburg (4), Sachsen (13), Sachsen-Anhalt (14), and Thüringen (16)

**********Demographics summary***********
tab gender
tab age
tab income
tab employment1_cat
tab employment2_cat
tab parental_status
tab bmi_cat
tab politicallean_cat
tab hypertension
tab cholesterol
tab CVD
tab diabetes
tab nutritiondisease_cat
tab formergdr

*****************************************OPT OUT TENDENCY ANALYSES*********************************************

//PREP: INPUT VARIABLES (Globals, Standardizing independent variables)

**********Generating globals***********
global socios gender age income parental_status formergdr politicallean_cat 
global healthdata nutritiondisease_cat bmi_cat

**********Standardizing scale of demographic variables for logistic regressions***********
foreach var of varlist $socios $healthdata {
	egen `var'std = std(`var')
}
global sociosstd genderstd agestd incomestd parental_statusstd formergdrstd politicallean_catstd 
global healthdatastd nutritiondisease_catstd bmi_catstd

sum $sociosstd $healthdatastd

//PREP: OUTPUTS (Binary optout, Ever-optout, Number opt out, Packaging resistance)

**********Recoding optout to binary 0 or 1***********
forval i = 1/8 {
    local varname = "optout_" + "`i'" + "a"
    replace `varname' = 0 if `varname' == 1 
	replace `varname' = 1 if `varname' == 3
	local varnameb = "optout_" + "`i'" + "b"
    replace `varnameb' = 0 if `varnameb' == 2
	replace `varnameb' = 1 if `varnameb' == 4
}

**********Generating dummy variable (ever_optout) for individual if they ever opted out of a policy package***********
gen ever_optout = 0
replace ever_optout = 1 if optout_1a == 1 | optout_1b == 1 | optout_2a == 1 | optout_2b == 1 | optout_3a == 1 | optout_3b == 1 | optout_4a == 1 | optout_4b == 1 | optout_5a == 1 | optout_5b == 1 | optout_6a == 1 | optout_6b == 1 | optout_7a == 1 | optout_7b == 1 | optout_8a == 1 | optout_8b == 1 

**********Generating ordinal variable (number_optout) indicating how many times, if ever, participant opted out of policy package***********
ds optout_1a optout_1b optout_2a optout_2b optout_3a optout_3b optout_4a optout_4b optout_5a optout_5b optout_6a optout_6b optout_7a optout_7b optout_8a optout_8b 
egen number_optout = rowtotal(`r(varlist)')


forval i = 1/4 {
	sum $socios $healthdata if number_optout == `i'
}

**********Collapsing 'number optout' to 'opt out tendency' outcome variable***********
recode number_optout (0=0) (1=1) (2=1) (3=2) (4=2), gen(packaging_resistance) // 0 = packaging enthusiasts, 1-2 = inclined, 3-4 = packaging resistants 
 
 
//OLOGIT REGRESSION: OPT OUT TENDENCY 

**********Coefplot***********
ologit packaging_resistance $healthdatastd $sociosstd social_norm awareness legitimacy, vce(robust) or 
est sto packaging_resistance_model
coefplot, xline(1) eform ci //coefficient plot
esttab packaging_resistance_model using resistance.rtf, se label replace

**********Margins plot***********
ologit packaging_resistance $healthdatastd $sociosstd social_norm awareness legitimacy, vce(robust) or 
est sto packaging_resistance_model
margins, dydx ($healthdatastd $sociosstd social_norm awareness legitimacy) 
marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal //margins plot
esttab packaging_resistance_model using resistance.rtf, se label replace

******Model excluding beliefs*******
ologit packaging_resistance $healthdatastd $sociosstd, vce(robust) or 
est sto packaging_resistance_model
coefplot, xline(1) eform ci //coefficient plot

ologit packaging_resistance $healthdatastd $sociosstd, vce(robust) or 
est sto packaging_resistance_model
margins, dydx ($healthdatastd $sociosstd) 
marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal //margins plot
esttab packaging_resistance_model using resistance.rtf, se label replace

****************************************IDEAL POLICY INTERVENTION ANALYSES*************************************

//PREP: OUTPUT VARIABLES (Presence of policy measures in ideal package, number of policies in package, 4 categories of packaging - resistance -intervention, resistance - packaging, inclined, enthusiastic) 

**********Generating dummy outcome variables for presence of specific policies in ideal policy package***********
gen vatinc_present =  strpos(ideal_package_0_group, "1") > 0
gen tax_present =  strpos(ideal_package_0_group, "2") > 0
gen ks_present =  strpos(ideal_package_0_group, "3") > 0
gen water_present =  strpos(ideal_package_0_group, "4") > 0
gen nuted_present =  strpos(ideal_package_0_group, "6") > 0
gen public_present =  strpos(ideal_package_0_group, "7") > 0
gen vatdec_present =  strpos(ideal_package_0_group, "8") > 0

tab vatinc_present
tab tax_present
tab public_present
tab ks_present
tab water_present
tab nuted_present
tab vatdec_present

**********Generating outcome variable reflecting number of policies selected into ideal policy package***********
gen number_in_package = length(trim(ideal_package_0_group))-length(trim(subinstr(ideal_package_0_group,",","",.))) + 1
foreach number in "1" "2" "3" "4" "6" "7" "8" { 
	gen inpackagedummy_`number' = 0
	replace inpackagedummy_`number' = 1 if strpos(ideal_package_0_group, "`number'")
}
replace number_in_package = 0 if (ideal_package_0_group=="") //fixing error that codes empty packages to zero instead of 1 

**********Generating 'ideal policy intervention density' outcome variable - collapsing number_in_package to four categories***********
recode number_in_package (0=0) (1=1) (2=2) (3=2) (4=2) (5=2) (6=3) (7=3), gen(packaging_enthusiasm) // 0 = resistant - intervention, 1 = resistant - policy packaging, 2-5 = inclined, 6-7 = enthusiasts


//OLOGIT REGRESSION: IDEAL POLICY INTERVENTION DENSITY 

**********Coefplot***********
ologit packaging_enthusiasm $healthdatastd $sociosstd social_norm awareness legitimacy, vce(robust) or
coefplot, xline(1) eform ci
est sto choice_model
esttab choice_model using enthusiasm.rtf, se label replace wide 

**********Margins plot***********
ologit packaging_enthusiasm $healthdatastd $sociosstd social_norm awareness legitimacy, vce(robust) or 
margins, dydx ($healthdatastd $sociosstd social_norm awareness legitimacy) 
marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal
esttab packaging_enthusiasm_model using enthusiasm.rtf, se label replace wide

******Model excluding beliefs*******

ologit packaging_enthusiasm $healthdatastd $sociosstd, vce(robust) or 
coefplot, xline(1) eform ci
est sto choice_model
esttab choice_model using enthusiasm.rtf, se label replace wide 

est sto packaging_enthusiasm_model
margins, dydx ($healthdatastd $sociosstd) //margins plot
marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal
esttab packaging_enthusiasm_model using enthusiasm.rtf, se label replace

//INTERACTION EFFECTS OF PACKAGED POLICIES IN IDEAL POLICY INTERVENTION - SINGLE MEASURES (Table 3)

gen vatinc_tax=0  
replace vatinc_tax=1 if(vatinc_present==1&tax_present==1)
gen vatinc_public=0  
replace vatinc_public=1 if(vatinc_present==1&public_present==1)
gen vatinc_ks=0  
replace vatinc_ks=1 if(vatinc_present==1&ks_present==1)
gen vatinc_water=0  
replace vatinc_water=1 if(vatinc_present==1&water_present==1)
gen vatinc_nuted=0  
replace vatinc_nuted=1 if(vatinc_present==1&nuted_present==1)
gen vatinc_vatdec=0  
replace vatinc_vatdec=1 if(vatinc_present==1&vatdec_present==1) // end of vat inc interactions

gen tax_public=0  
replace tax_public=1 if(tax_present==1&public_present==1)
gen tax_ks=0  
replace tax_ks=1 if(tax_present==1&ks_present==1)
gen tax_water=0  
replace tax_water=1 if(tax_present==1&water_present==1)
gen tax_nuted=0  
replace tax_nuted=1 if(tax_present==1&nuted_present==1)
gen tax_vatdec=0  
replace tax_vatdec=1 if(tax_present==1&vatdec_present==1) // end of ssb tax interactions interactions

gen public_ks=0  
replace public_ks=1 if(public_present==1&ks_present==1)
gen public_water=0  
replace public_water=1 if(public_present==1&water_present==1)
gen public_nuted=0  
replace public_nuted=1 if(public_present==1&nuted_present==1)
gen public_vatdec=0  
replace public_vatdec=1 if(public_present==1&vatdec_present==1) // end of mandatory public standards for public institutions interactions interactions

gen ks_water=0  
replace ks_water=1 if(ks_present==1&water_present==1)
gen ks_nuted=0  
replace ks_nuted=1 if(ks_present==1&nuted_present==1)
gen ks_vatdec=0  
replace ks_vatdec=1 if(ks_present==1&vatdec_present==1) // end of mandatory public standards for K&S interactions interactions

gen water_nuted=0  
replace water_nuted=1 if(water_present==1&nuted_present==1)
gen water_vatdec=0  
replace water_vatdec=1 if(water_present==1&vatdec_present==1) //end of water interactions

gen nuted_vatdec=0
replace nuted_vatdec=1 if(nuted_present==1&vatdec_present==1) //end of nuted interactions

//PACKAGING OF 'POSITIVE' AND 'NEGATIVE' POLICIES IN IDEAL POLICY INTERVENTION

******Effect on choice - Enable/inform + guide by incentive; Restrict + guide by disincentive*******

gen supportchoice_only=0
replace supportchoice_only=1 if (vatdec_present==1 | nuted_present==1 | water_present==1) & (ks_present==0 & public_present==0 & tax_present==0 & vatinc_present==0)

gen restrictchoice_only=0
replace restrictchoice_only=1 if (ks_present==1 | public_present==1 | tax_present==1 | vatinc_present==1) & (vatdec_present==0 & nuted_present==0 & water_present==0)

gen support_restrict=0
replace support_restrict=1 if (vatdec_present==1 | nuted_present==1 | water_present==1) & (ks_present==0 | public_present==0 | tax_present==0 | vatinc_present==0)

gen neither=0
replace neither=1 if (ks_present==0 & public_present==0 & tax_present==0 & vatinc_present==0 & vatdec_present==0 & nuted_present==0 & water_present==0)

******Mechanism - Fiscal vs. behavioral policies******

gen fiscal_only=0
replace fiscal_only=1 if (vatinc_present==1 | tax_present==1 | vatdec_present==1) & (nuted_present==0 & ks_present==0 & public_present==0 & water_present==0)

gen behavioral_only=0
replace behavioral_only=1 if (nuted_present==1 | ks_present==1 | public_present==1 | water_present==1) & (vatinc_present==0 & tax_present==0 & vatdec_present==0) 

gen fiscal_behavioral=0
replace fiscal_behavioral=1 if (nuted_present==1 | ks_present==1 | public_present==1 | water_present==1) & (vatinc_present==1 | tax_present==1 | vatdec_present==1)


******Population targeting - targeted vs. non-targeted*******

gen targeted_only=0
replace targeted_only=1 if (nuted_present==1 | ks_present==1) & (vatinc_present==0 & tax_present==0 & public_present==0 & water_present==0 & vatdec_present==0)

gen nontargeted_only=0
replace nontargeted_only=1 if (vatinc_present==1 | tax_present==1 | public_present==1 | water_present==1 & vatdec_present==1) & (nuted_present==0 & ks_present==0)

gen targeted_nontargeted=0
replace targeted_nontargeted=1 if (nuted_present==1 | ks_present==1) & (vatinc_present==1 | tax_present==1 | public_present==1 | water_present==1 & vatdec_present==1)


******Effect on support - 'Negative' vs. 'Positive' policies*******
gen negative_only=0 //only negative policies
replace negative_only=1 if (vatinc_present==1 | tax_present==1) & (vatdec_present==0 & nuted_present==0 & ks_present==0)

gen positive_only=0
replace positive_only=1 if (vatdec_present==1 | nuted_present==1 | ks_present==1) & (vatinc_present==0 & tax_present==0)

gen positive_negative=0
replace positive_negative=1 if (vatinc_present==1 | tax_present==1) & (vatdec_present==1 | nuted_present==1 | ks_present==1)


****CROSS REFERENCING PACKAGING ENTHUSIASM AND PACKAGING RESISTANCE ACROSS OPT OUT AND IDEAL POLICY PACKAGE OUTCOMES*******

//A = opt out _ B = ideal policy package
gen resistant_resistantint=0
replace resistant_resistantint=1 if(packaging_resistance==2&packaging_enthusiasm==0)
gen resistant_resistantpack=0
replace resistant_resistantpack=1 if(packaging_resistance==2&packaging_enthusiasm==1)
gen resistant_inclined=0
replace resistant_inclined=1 if(packaging_resistance==2&packaging_enthusiasm==2)
gen resistant_enthusiast=0
replace resistant_enthusiast=1 if(packaging_resistance==2&packaging_enthusiasm==3)

gen inclined_resistantint=0
replace inclined_resistantint=1 if(packaging_resistance==1&packaging_enthusiasm==0)
gen inclined_resistantpack=0
replace inclined_resistantpack=1 if(packaging_resistance==1&packaging_enthusiasm==1)
gen inclined_inclined=0
replace inclined_inclined=1 if(packaging_resistance==1&packaging_enthusiasm==2)
gen inclined_enthusiast=0
replace inclined_enthusiast=1 if(packaging_resistance==1&packaging_enthusiasm==3)

gen enthusiast_resistantint=0
replace enthusiast_resistantint=1 if(packaging_resistance==0&packaging_enthusiasm==0)
gen enthusiast_resistantpack=0
replace enthusiast_resistantpack=1 if(packaging_resistance==0&packaging_enthusiasm==1)
gen enthusiast_inclined=0
replace enthusiast_inclined=1 if(packaging_resistance==0&packaging_enthusiasm==2)
gen enthusiast_enthusiast=0
replace enthusiast_enthusiast=1 if(packaging_resistance==0&packaging_enthusiasm==3)

**********Generating variables to reflect, when participants opted out of a policy package, which policy they chose******

gen optout_public=0
replace optout_public=1 if (optoutselect_1a==1 | optoutselect_1b==1 | optoutselect_2a==1 | optoutselect_2b==1 | optoutselect_3a==1 | optoutselect_3b==1 | optoutselect_4a==1 | optoutselect_4b==1 | optoutselect_5a==1 | optoutselect_5b==1 | optoutselect_6a==1 | optoutselect_6b==1 | optoutselect_7a==1 | optoutselect_7b==1 | optoutselect_8a==1 | optoutselect_8b==1)

gen optout_vatinc=0
replace optout_vatinc=1 if (optoutselect_1a==2 | optoutselect_1b==2 | optoutselect_2a==2 | optoutselect_2b==2 | optoutselect_3a==2 | optoutselect_3b==2 | optoutselect_4a==2 | optoutselect_4b==2 | optoutselect_5a==2 | optoutselect_5b==2 | optoutselect_6a==2 | optoutselect_6b==2 | optoutselect_7a==2 | optoutselect_7b==2 | optoutselect_8a==2 | optoutselect_8b==2)

gen optout_vatdec=0
replace optout_vatdec=1 if (optoutselect_1a==3 | optoutselect_1b==3 | optoutselect_2a==3 | optoutselect_2b==3 | optoutselect_3a==3 | optoutselect_3b==3 | optoutselect_4a==3 | optoutselect_4b==3 | optoutselect_5a==3 | optoutselect_5b==3 | optoutselect_6a==3 | optoutselect_6b==3 | optoutselect_7a==3 | optoutselect_7b==3 | optoutselect_8a==3 | optoutselect_8b==3)

gen optout_tax=0
replace optout_tax=1 if (optoutselect_1a==4 | optoutselect_1b==4 | optoutselect_2a==4 | optoutselect_2b==4 | optoutselect_3a==4 | optoutselect_3b==4 | optoutselect_4a==4 | optoutselect_4b==4 | optoutselect_5a==4 | optoutselect_5b==4 | optoutselect_6a==4 | optoutselect_6b==4 | optoutselect_7a==4 | optoutselect_7b==4 | optoutselect_8a==4 | optoutselect_8b==4)

gen optout_ks=0
replace optout_ks=1 if (optoutselect_1a==5 | optoutselect_1b==5 | optoutselect_2a==5 | optoutselect_2b==5 | optoutselect_3a==5 | optoutselect_3b==5 | optoutselect_4a==5 | optoutselect_4b==5 | optoutselect_5a==5 | optoutselect_5b==5 | optoutselect_6a==5 | optoutselect_6b==5 | optoutselect_7a==5 | optoutselect_7b==5 | optoutselect_8a==5 | optoutselect_8b==5)

gen optout_water=0
replace optout_water=1 if (optoutselect_1a==6 | optoutselect_1b==6 | optoutselect_2a==6 | optoutselect_2b==6 | optoutselect_3a==6 | optoutselect_3b==6 | optoutselect_4a==6 | optoutselect_4b==6 | optoutselect_5a==6 | optoutselect_5b==6 | optoutselect_6a==6 | optoutselect_6b==6 | optoutselect_7a==6 | optoutselect_7b==6 | optoutselect_8a==6 | optoutselect_8b==6)

gen optout_nuted=0
replace optout_nuted=1 if (optoutselect_1a==7 | optoutselect_1b==7 | optoutselect_2a==7 | optoutselect_2b==7 | optoutselect_3a==7 | optoutselect_3b==7 | optoutselect_4a==7 | optoutselect_4b==7 | optoutselect_5a==7 | optoutselect_5b==7 | optoutselect_6a==7 | optoutselect_6b==7 | optoutselect_7a==7 | optoutselect_7b==7 | optoutselect_8a==7 | optoutselect_8b==7)

tab optout_public
tab optout_vatinc
tab optout_vatdec
tab optout_tax
tab optout_ks
tab optout_water
tab optout_nuted





 
